import os
import requests
from concurrent.futures import ThreadPoolExecutor


def download(file_name, url):
    res = requests.get(
        url=url,
        headers={
        "User-Agent": "Nozilla/5"
    })


    #检査images目录是否存在?不存在，则创建images目录if not os.path.exists("images"):# 创建images日录
    os.makedirs("images")
    file_path = os.path.join("images", file_name)#2.将图片的内容写入到文件
    with open(file_path, mode='wb') as img_object:
        img_object.write(res.content)


# 创建线程池，最多维护18个线程。
pool = ThreadPoolExecutor(10)
with open("mv.csv", mode='r', encoding='utf-8') as file_object:
    for line in file_object:
        nid, name, url = line.split(",")
        file_name ="{}.png".format(name)
        pool.submit(download, file_name, url)